package org.example.test;

import org.reactivestreams.Publisher;
import reactor.core.publisher.Mono;
import reactor.netty.http.server.HttpServer;
import reactor.netty.http.server.HttpServerResponse;

public class WebServer4 {
    public static final int PORT = 8080;

    public static void main(String[] args) {
        HttpServer.create()
                .port(PORT)
                .route(routes ->
                        routes.get("/user/{id}", (request, response) -> {
                            String userId = request.param("id");
                            // 根据userId获取用户信息的业务逻辑
                            return getUserInfo(userId,response);
                        })
                )
                .bindNow()
                .onDispose()
                .block();
    }

    private static Publisher<Void> getUserInfo(String userId, HttpServerResponse response) {
        // 获取用户信息的逻辑
        return response.sendString(Mono.just("User " + userId + " Info"));
//        return Mono.just("User " + userId + " Info");
    }
}
